
package com.gitee.jmash.storage.service;

import com.gitee.jmash.core.orm.DtoPage;
import com.gitee.jmash.core.orm.DtoTotal;
import com.gitee.jmash.core.orm.cdi.JpaTenantService;
import com.gitee.jmash.core.orm.jpa.TenantEntityManager;
import com.gitee.jmash.core.orm.tenant.TenantService;
import com.gitee.jmash.core.transaction.JakartaTransaction;
import com.gitee.jmash.storage.dao.StorageOrganBrowserDao;
import com.gitee.jmash.storage.dao.StorageOrganInfoDao;
import com.gitee.jmash.storage.entity.StorageOrganBrowserEntity;
import com.gitee.jmash.storage.entity.StorageOrganBrowserEntity.StorageOrganBrowserPk;
import jmash.storage.protobuf.StorageOrganBrowserReq;
import jakarta.enterprise.inject.Typed;
import jakarta.enterprise.inject.spi.CDI;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jakarta.transaction.Transactional;
import jakarta.transaction.Transactional.TxType;
import jakarta.validation.executable.ValidateOnExecution;
import java.util.List;
import java.util.UUID;

/**
 * 组织浏览信息 storage_organ_browser读服务.
 *
 * @author <a href="mailto:service@crenjoy.com">crenjoy</a>
 */
@Typed(StorageOrganBrowserRead.class)
@Transactional(TxType.SUPPORTS)
@JpaTenantService
@ValidateOnExecution
public class StorageOrganBrowserReadBean implements StorageOrganBrowserRead, JakartaTransaction {

  protected TenantEntityManager tem = new TenantEntityManager();

  protected StorageOrganInfoDao storageOrganInfoDao = new StorageOrganInfoDao(tem);
  protected StorageOrganBrowserDao storageOrganBrowserDao = new StorageOrganBrowserDao(tem);

  @PersistenceContext(unitName = "ReadStorage")
  public void setEntityManager(EntityManager entityManager) {
    this.tem.setEntityManager(entityManager,false);
  }
	
  @Override
  public EntityManager getEntityManager() {
    return this.tem.getEntityManager();
  }

  @Override
  @SuppressWarnings("unchecked")
  public <T extends TenantService> T setTenant(String tenant) {
    this.tem.setTenant(tenant);
    return (T) this;
  }
  
  @Override
  public void setTenantOnly(String tenant) {
     this.tem.setTenantOnly(tenant);
  }

  @Override
  public String getTenant() {
    return this.tem.getTenant();
  }

  @Override
  public StorageOrganBrowserEntity findById(StorageOrganBrowserPk entityId) {
    return storageOrganBrowserDao.find(entityId);
  }


  @Override
  public DtoPage<StorageOrganBrowserEntity,DtoTotal> findPageByReq(StorageOrganBrowserReq req) {
    return storageOrganBrowserDao.findPageByReq(req);
  }

  @Override
  public List<StorageOrganBrowserEntity> findListByReq(StorageOrganBrowserReq req) {
    return storageOrganBrowserDao.findListByReq(req);
  }
  
  @Override
  public void close() throws Exception {
    CDI.current().destroy(this);
  }
}
